<?php
$serv = new swoole_server('0.0.0.0', 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$serv->set(array(
    'worker_num' => 4,
    'daemonize' => false,
    'task_worker_num' => 4,
    'backlog' => 128,
));

$serv->on('Start', 'onStart');
$serv->on('Connect', 'onConnect');
$serv->on('Receive', 'onReceive');
$serv->on('Close', 'onClose');
$serv->on('Task', 'onTask');
$serv->on('Finish', 'onFinish');

function onStart(swoole_server $server){
    echo "onStart\n";
}

function onConnect(swoole_server $server, $fd, $reactorId)
{
    echo "onConnect\n";
}

function onReceive(swoole_server $server, $fd, $reactor_id, $data){

    echo "onReceive\n";
    var_dump($data);
    $server->send($fd, 'onReceive'.$data);
    $server->close($fd);
}

// $serv->on('receive', function ($serv, $fd, $from_id, $data) {
// 	echo "onReceive\n";
//     $serv->send($fd, 'Swoole: '.$data);
//     $serv->close($fd);
// });

function onClose(swoole_server $server, $fd, $reactorId)
{
    echo "onClose\n";
}

function onTask(swoole_server $serv, $task_id, $src_worker_id, $data)
{
    echo "onTask\n";
}

function onFinish(swoole_server $serv, $task_id, $data)
{
    echo "onFinish\n";
}

$serv->start();
